/////////////////////////////////////////////////////////////////////////
// File:        TNodAppBase.h
// Purpose:     Interface for an Application which can use the TNodBase
//              Class to download valid licenses and to check new 
//              versions of this application
// Author:      Tukero
// Modified by: 
// Copyright:   (c) Tukero <tukero@gmail.com>
// Licence:     GNU/LGPL v3
/////////////////////////////////////////////////////////////////////////

#ifndef _TNODAPPBASE_H_
#define _TNODAPPBASE_H_

#ifndef _WIN32_IE
#  define _WIN32_IE 0x0501
#elif _WIN32_IE < 0x0501
#  error This application requires Internet Explorer 5.01 or latter
#endif

#ifdef __BORLANDC__
#  pragma hdrstop
#endif

#ifndef WX_PRECOMP
#  include <wx/wx.h>
#else
#  include <wx/wxprec.h>
#endif

#include <windows.h>
#include <wx/config.h>           //for read/write application settings
#include <wx/thread.h>

#include "TrayIcon.h"
#include "version.h"
#include "Settings.h"
#include "TNodBase.h"

//Application modes: normal, hidden and configuration
enum APPMODE
{
	NORMALMODE = 0,
	HIDDENMODE,
	CONFIGMODE
};

//class TNod;

// -----------------------------------------------------------------------------------------
// Frame used to show Dialogs 
// All GUIs must be created in the main thread (TNodApp) to work correctly.
// --------------------------------------------------------------------------------------
class DialogsWindow : public wxFrame
{    
public:    
    DialogsWindow();
    void OnCommand(wxCommandEvent& event);
    DECLARE_EVENT_TABLE()
};


// --------------------------------------------------------------------------------------
// main application class
// --------------------------------------------------------------------------------------
class TNodAppBase abstract : public wxApp
{
private:
    //wxConfig*       m_GlobalConfigManager;
    ConfigManager*  m_GlobalConfigManager;
    TNodSettings*   m_GlobalSettings;
    wxFrame*        m_DialogsWindow;    
protected:
    TNodBase*       m_TNod;
    //wxThread*       m_TrayIconThread;
    //wxFrame*        m_DownloadLicensesFrm;    
    TrayIcon*       m_TrayIcon;

    //void         CloseTNodThreads();
    //wxFrame*        m_SettingsDlg;    
public:    
    TNodAppBase();    
    long            m_Mode;
    wxMenu          *m_MenuShown;
    
    bool            m_NewVersionFound;
    bool            m_IsInputFinished;

    unsigned int    m_validLicenses2Get;
    int             m_licensesNum2Check;

    //volatile int    m_checkedLicenses;

    wxCriticalSection   m_MutexValidLicensesList;
    //wxCriticalSection   m_MutexLicensesCounter;
    wxCriticalSection   m_MutexThreadsList;
    
    virtual void Finish();

    virtual bool OnInit();
    virtual int  OnExit();

    virtual TrayIcon*   CreateTrayIcon();
    static  wxString    GetStrVersion(int tipo = 0);
    virtual wxString    GetBalloonTitle();
    virtual void        ChangeMsgBalloon(short flagicon, wxString message, bool ChangeOnly = false, bool append = false, bool isNewVersionMsg = false);    
    virtual void        ManageWindow(const wxString command, void *data2Send = NULL);
    virtual void        ManageIcon(const int action = 0, const wxString params = wxT(""));    
};

#endif